const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } =require('clean-webpack-plugin')

module.exports = {
    entry: './src/index.ts',

    mode: 'development',
    output: {
        path: path.resolve(__dirname, './dist'),
        filename: 'bundle.js',
        // https://webpack.js.org/configuration/output/, 输出文件不使用箭头函数
        environment: {
            arrowFunction: false
        }
    },


    resolve: {
        extensions: ['.ts', '.js', '.vue']
    },

    module: {
        rules: [
            {
                test: /\.less$/,
                use: [
                    "style-loader",
                    "css-loader",
                    "less-loader"
                ]
            },
            {
                test: /\.ts$/,
                use: [
                    {
                        loader: 'babel-loader',
                        // 设置loader
                        options: {
                            // 设置定义的环境
                            presets: [
                                [
                                    // 指定环境的插件
                                    '@babel/preset-env',
                                    // 配置信息
                                    {
                                        // 兼容目标浏览器
                                        targets: {
                                            "chrome": '58',
                                            "ie": '9'
                                        },
                                        // core版本
                                        "corejs": "3",
                                        // 使用core方式，usage - 按需加载
                                        "useBuiltIns": "usage"
                                    }
                                ]
                            ]
                        }
                    },
                    'ts-loader'
                ],  // ts -> js（新） -> js(旧)
                exclude: '/node_modules/'
            }
        ]
    },

    plugins: [
        new CleanWebpackPlugin(),

        new HtmlWebpackPlugin({
            template: './src/indexTemplate.html'
        })
    ],
    
}